package charts.plot
{
	import mx.core.UIComponent;
	import flash.display.Sprite;
	import mx.core.EdgeMetrics;
	import charts.debug.Log;
	
	
	[Style(name="showBorder",type="Boolean",inherit="no")]
	[Style(name="showFill",type="Boolean",inherit="no")]
	[Style(name="borderWeight",type="Number",inherit="no")]
	[Style(name="borderColor",type="Number",format="Color",inherit="no")]
	[Style(name="fillColor",type="Number",format="Color",inherit="no")]
	
	public class PlotArea extends UIComponent
	{
		include "../core/Version.as";
		
		///////////////////////////////////////
		// Setting default style values
		private static var defaultStyles:Object = 
		{
			showFill: true,
			showBorder: true,
			borderColor: 0x0033333,
			borderWeight: 2,
			fillColor: 0x1200EF
		};
		private static var myClassName:String = "PlotArea";
		include "../core/defaultStyles.as";
		//////////////////////////////////////

		//--Children
		private var _series:Array = [];
		protected var _edgeMetrics:EdgeMetrics = new EdgeMetrics();
		
		
		public function PlotArea()
		{
			super();
		}
		
		public function set series(value:Array):void
		{
			
		}
		
		/**
		 *  Some types of plot areas have a limited drawing area. This indicates
		 *  the size of the borders or labels.
		 */
		public function get edgeMetrics():EdgeMetrics
		{
			return this._edgeMetrics;
		}
		
		/**
    	 *  Draws the border and fill of the plot area
    	 */
		override protected function updateDisplayList(unscaledWidth:Number,
                                        			  unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			Log.p("PlotArea::updateDisplayList()");
			
			
			this.graphics.clear();
			
			var showBorder:Boolean = this.getStyle("showBorder");
			var showFill:Boolean = this.getStyle("showFill");
			// Draws the border and fill of the plot area
			if(showBorder || showFill)
			{
				var borderWeight:Number = this.getStyle("borderWeight");
				var borderColor:Number = this.getStyle("borderColor");
				var fillColor:Number = this.getStyle("fillColor");
				
				if(showFill) this.graphics.beginFill(fillColor, 1.0);
					
				if(showBorder && borderWeight>0) this.graphics.lineStyle(borderWeight, borderColor, 1.0);
				else this.graphics.lineStyle(0, 0, 0);
				
				var fillWidth:Number = unscaledWidth - this._edgeMetrics.left - this._edgeMetrics.right;
				var fillHeight:Number = unscaledHeight - this._edgeMetrics.top - this._edgeMetrics.bottom;
				
				this.graphics.drawRect(this._edgeMetrics.left, this._edgeMetrics.top, fillWidth, fillHeight);
				
				if(showFill) this.graphics.endFill();
			}
			
		}
		
		override public function styleChanged(styleProp:String):void
    	{
    		super.styleChanged(styleProp);
    		
    		if(styleProp == "showBorder" || 
    		   styleProp == "showFill" ||
    		   styleProp == "borderWeight" || 
    		   styleProp == "borderColor" ||
    		   styleProp == "fillColor")
    			this.invalidateDisplayList();
    	}
		
		/*
		
		override protected function createChildren():void
		{
			super.createChildren();
		}
		override protected function measure():void
		{
			super.measure();
		}
		override protected function commitProperties():void
		{
			super.commitProperties();
		}
		override public function styleChanged(styleProp:String):void
    	{
    		super.styleChanged(styleProp);
    	} */
	}
}